package com.chis.flink;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketData {

    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(9000);
            System.out.println("启动服务器....");
            Socket socket = serverSocket.accept();
            System.out.println("客户端:" + socket.getInetAddress().getLocalHost() + "已连接到服务器");
            PrintWriter printWriter = new PrintWriter(socket.getOutputStream());
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            String line = bufferedReader.readLine();
            while (!line.equals("exit")){
                printWriter.println(line);
                printWriter.flush();
                line = bufferedReader.readLine();
            }
            printWriter.close();
            socket.close();
            serverSocket.close();
        } catch (Exception e){
            e.printStackTrace();
        }


    }
}
